home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
- Subject: Re: Access carry flag from C
- Date: Mon, 26 Feb 96 23:38:52 GMT
- Organization: none
- Message-ID: <825377932snz@genesis.demon.co.uk>
- References: <Dn1C9z.DGv.0.net@indra.com> <ARTHUR.96Feb20143404@gold.Smallworld.co.uk> <824853272snz@genesis.demon.co.uk> <4gqj0d$d6p@airdmhor.gen.nz>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4gqj0d$d6p@airdmhor.gen.nz>
- gumboot@airdmhor.gen.nz "Simon Hosie" writes:
-
- >Lawrence Kirby:
- >> It certainly can be done portably although not with the efficiency that
- >> a platform-specific solution is likely to give you.
- >
- >> int j, k;
- >
- >> ...
- >
- >> if ((j >= 0) ? (k > INT_MAX-j) : (k < INT_MIN-j))
- > ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
- > Won't they both be evaluated?
-
- No, given:
-
- (expr1) ? expr2 : (expr3)
-
- the (ANSI) C language guarantees that expr1 will be evaluated and followed
- by a sequence point. If expr1 evaluates to a value that compares unequal
- to zero then expr2 is evaluated, otherwise expr3 is evaluated. Under no
- circumstances (except undefined behaviour caused by something else in the
- program, where anything can happen) can both expr2 and expr3 be evaluated.
-
- You probably noticed that I didn't put parentheses around expr2. Can you
- see why they are necessary around expr1 and expr3 but not here? (This does
- test understanding of expression parsing quite deeply).
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-